package solution;

import common.ListNode;
import common.util.ListNodeUtil;

/**
 * @author : wenchao.long
 * @date : Created in 2023-12-19 下午 6:58 周二
 * @description :
 */
public class No2 {

	public static ListNode addTwoNumbers(ListNode l1, ListNode l2) {
		return getNode(l1, l2, 0);
	}

	private static ListNode getNode(ListNode l1, ListNode l2, int mode) {
		if (l1 == null && l2 == null && mode == 0) {
			return null;
		}
		int val = mode;
		if (l1 != null) {
			val += l1.val;
			l1 = l1.next;
		}
		if (l2 != null) {
			val += l2.val;
			l2 = l2.next;
		}
		ListNode node = new ListNode(val % 10);
		node.next = getNode(l1, l2, val / 10);
		return node;
	}

	public static void main(String[] args) {
		ListNode listNode = addTwoNumbers(ListNodeUtil.create(9, 9, 9, 9, 9, 9, 9), ListNodeUtil.create(9, 9, 9, 9));
		System.out.println(listNode);
	}
}




